package com.wrupple.muba.catalogs.server.domain;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.gwt.event.shared.UmbrellaException;
import com.wrupple.muba.catalogs.server.service.CatalogDataAccessObject;
import com.wrupple.muba.catalogs.server.service.CatalogSummaryBuilder;
import com.wrupple.muba.common.domain.FilterData;
import com.wrupple.vegetate.domain.CatalogObject;

public class POJOCatalogActionStateBag implements CatalogActionStateBag {
	String targetCatalogName;
	String targetAction;
	String targetEntryId;
	CatalogDataAccessObject<? extends CatalogObject> targetCatalogDao;
	String[] rawData;
	CatalogObject[] data;
	Set<Throwable> collectedException;
	CatalogSummaryBuilder summaryBuilder;
	FilterData[] filterData;
	List<CatalogObject> commitingResult;
	private String callbackFunctionName;
	
	
	public POJOCatalogActionStateBag() {
		super();
		collectedException =new HashSet<Throwable>();
	}
	public String[] getRawData() {
		return rawData;
	}
	public void setRawData(String[] rawData) {
		this.rawData = rawData;
	}
	public CatalogObject[] getData() {
		return data;
	}
	public void setData(CatalogObject[] data) {
		this.data = data;
	}
	public Throwable getCollectedException() {
		if(collectedException.isEmpty()){
			return null;
		}else{
			if(collectedException.size()==1){
				return collectedException.iterator().next();
			}
		}
		return new UmbrellaException(this.collectedException);
	}
	public void setCollectedException(Throwable collectedException) {
		this.collectedException.add(collectedException);
	}
	public CatalogSummaryBuilder getSummaryBuilder() {
		return summaryBuilder;
	}
	public void setSummaryBuilder(CatalogSummaryBuilder summaryBuilder) {
		this.summaryBuilder = summaryBuilder;
	}
	public FilterData[] getFilterData() {
		return filterData;
	}
	public void setFilterData(FilterData[] filterData) {
		this.filterData = filterData;
	}
	public List<CatalogObject> getCommitingResult() {
		return commitingResult;
	}
	public void setCommitingResult(List<CatalogObject> commitingResult) {
		this.commitingResult = commitingResult;
	}
	public String getTargetCatalogName() {
		return targetCatalogName;
	}
	public void setTargetCatalogName(String targetCatalogName) {
		this.targetCatalogName = targetCatalogName;
	}
	public String getTargetAction() {
		return targetAction;
	}
	public void setTargetAction(String targetAction) {
		this.targetAction = targetAction;
	}
	public String getTargetEntryId() {
		return targetEntryId;
	}
	public void setTargetEntryId(String targetEntryId) {
		this.targetEntryId = targetEntryId;
	}
	public CatalogDataAccessObject<? extends CatalogObject> getTargetCatalogDao() {
		return targetCatalogDao;
	}
	public void setTargetCatalogDao(
			CatalogDataAccessObject<? extends CatalogObject> targetCatalogDao) {
		this.targetCatalogDao = targetCatalogDao;
	}
	@Override
	public String toString() {
		return "POJOCatalogActionStateBag [targetCatalogName="
				+ targetCatalogName + ", targetAction=" + targetAction
				+ ", targetEntryId=" + targetEntryId + ", targetCatalogDao="
				+ targetCatalogDao + ", rawData=" + Arrays.toString(rawData)
				+ ", data=" + Arrays.toString(data) + ", collectedException="
				+ collectedException + ", summaryBuilder=" + summaryBuilder
				+ ", filterData=" + Arrays.toString(filterData)
				+ ", commitingResult=" + commitingResult + "]";
	}
	@Override
	public String getCallbackFunctionName() {
		return callbackFunctionName;
	}
	@Override
	public void setCallbackFunctionName(String function) {
		callbackFunctionName=function;
	}

}
